/*    */ package com.zimbra.cs.datasource;
/*    */ 
/*    */ import com.google.common.collect.ImmutableSet;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.DataSource;
/*    */ import com.zimbra.cs.mailbox.Folder;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import com.zimbra.cs.mailbox.MailboxListener;
/*    */ import com.zimbra.cs.mailbox.MailboxListener.ChangeNotification;
/*    */ import com.zimbra.cs.session.PendingModifications;
/*    */ import com.zimbra.cs.session.PendingModifications.Change;
/*    */ import com.zimbra.cs.session.PendingModifications.ModificationKey;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import java.util.Map.Entry;
/*    */ import java.util.Set;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class DataSourceListener
/*    */   extends MailboxListener
/*    */ {
/* 37 */   public static final ImmutableSet<MailItem.Type> ITEMTYPES = ImmutableSet.of(MailItem.Type.FOLDER);
/*    */   
/*    */ 
/*    */ 
/*    */   public void notify(MailboxListener.ChangeNotification notification)
/*    */   {
/* 43 */     if (notification.mods.deleted != null) {
/* 44 */       for (Map.Entry<PendingModifications.ModificationKey, PendingModifications.Change> entry : notification.mods.deleted.entrySet()) {
/* 45 */         MailItem.Type type = (MailItem.Type)((PendingModifications.Change)entry.getValue()).what;
/* 46 */         if (type == MailItem.Type.FOLDER) {
/* 47 */           Folder oldFolder = (Folder)((PendingModifications.Change)entry.getValue()).preModifyObj;
/* 48 */           if (oldFolder == null) {
/* 49 */             ZimbraLog.datasource.warn("Cannot determine the old folder name for %s.", new Object[] { entry.getKey() });
/*    */           } else {
/*    */             try
/*    */             {
/* 53 */               ZimbraLog.datasource.info("Deleting datasources that reference %s.", new Object[] { oldFolder.getPath() });
/* 54 */               account = oldFolder.getAccount();
/* 55 */               List<DataSource> datasources = account.getAllDataSources();
/* 56 */               for (DataSource datasource : datasources)
/* 57 */                 if (datasource.getFolderId() == oldFolder.getId()) {
/* 58 */                   ZimbraLog.datasource.debug("Deleting datasource %s.", new Object[] { datasource.getName() });
/* 59 */                   account.deleteDataSource(datasource.getId());
/*    */                 }
/*    */             } catch (ServiceException e) {
/*    */               Account account;
/* 63 */               ZimbraLog.datasource.warn("Could not delete datasources for folder.", new Object[] { oldFolder.getPath() });
/*    */             }
/*    */           }
/*    */         }
/*    */       }
/*    */     }
/*    */   }
/*    */   
/*    */   public Set<MailItem.Type> registerForItemTypes() {
/* 72 */     return ITEMTYPES;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/datasource/DataSourceListener.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */